package service

import (
	"api-wareway/basic/config"
	__ "api-wareway/basic/proto"
	"api-wareway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddMember(c *gin.Context) {
	var form request.AddMemberForm

	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "校验失败",
		})
		return
	}

	member, err := config.VideoClient.AddMember(c, &__.AddMemberReq{
		UserId:     int64(form.UserId),
		MemberTime: form.MemberTime,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "续费失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "续费成功",
		"data": member,
	})
}

func AddVideo(c *gin.Context) {
	var form request.AddVideoForm

	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "校验失败",
		})
		return
	}

	video, err := config.VideoClient.AddVideo(c, &__.AddVideoReq{
		Title:       form.Title,
		Image:       form.Image,
		Info:        form.Info,
		VideoListId: int64(form.VideoListId),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "发布失败",
			"data": err.Error(),
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "发布成功",
		"data": video,
	})

}
